/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package pt.iasd.youthshelter.datamodel;

import java.io.Serializable;
import java.sql.Blob;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Rui
 */
@Entity
@Table(name = "HONOR")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Honor.findAll", query = "SELECT h FROM Honor h"),
    @NamedQuery(name = "Honor.findById", query = "SELECT h FROM Honor h WHERE h.id = :id"),
    @NamedQuery(name = "Honor.findByName", query = "SELECT h FROM Honor h WHERE h.name = :name"),
    @NamedQuery(name = "Honor.findByDescription", query = "SELECT h FROM Honor h WHERE h.description = :description")})
public class Honor implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID")
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 200)
    @Column(name = "NAME")
    private String name;
    @Size(max = 1000)
    @Column(name = "DESCRIPTION")
    private String description;
    @Lob
    @Column(name = "PHOTO")
    private Blob photo;
    @JoinTable(name = "HONOR_DEPENDENCIES", joinColumns = {
        @JoinColumn(name = "HONOR_ID", referencedColumnName = "ID")}, inverseJoinColumns = {
        @JoinColumn(name = "DEPENDENCY_ID", referencedColumnName = "ID")})
    @ManyToMany
    private List<Honor> dependencyList;
    @ManyToMany(mappedBy = "honorList")
    private List<Investiture> investitureList;
    @ManyToMany(mappedBy = "honorList")
    private List<Club> clubList;

    public Honor() {
    }

    public Honor(Integer id) {
        this.id = id;
    }

    public Honor(Integer id, String name) {
        this.id = id;
        this.name = name;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Blob getPhoto() {
        return photo;
    }

    public void setPhoto(Blob photo) {
        this.photo = photo;
    }

    @XmlTransient
    public List<Honor> getDependencyList() {
        return dependencyList;
    }

    public void setDependencyList(List<Honor> dependencyList) {
        this.dependencyList = dependencyList;
    }

    @XmlTransient
    public List<Investiture> getInvestitureList() {
        return investitureList;
    }

    public void setInvestitureList(List<Investiture> investitureList) {
        this.investitureList = investitureList;
    }

    @XmlTransient
    public List<Club> getClubList() {
        return clubList;
    }

    public void setClubList(List<Club> clubList) {
        this.clubList = clubList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Honor)) {
            return false;
        }
        Honor other = (Honor) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "pt.iasd.youthshelter.datamodel.Honor[ id=" + id + " ]";
    }
    
}
